package com.LFLWZ.controller;

import com.LFLWZ.beans.Dto.Dto;
import com.LFLWZ.beans.POJO.LecturerApply;

import com.LFLWZ.service.LecturerApplyService;
import com.LFLWZ.utils.DtoUtil;
import com.LFLWZ.utils.EmptyUtils;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("lecturerapply")
public class LecturerApplyController {
    @Reference
    LecturerApplyService lecturerApplyService;

    @GetMapping("sel/{uid}")
    public Dto sel(@PathVariable Integer uid) {
        LecturerApply list = lecturerApplyService.queryById(uid);
        if (list == null) {
            return DtoUtil.returnError(4001, "查询失败");
        } else {
            return DtoUtil.returnSuccessData(list);
        }
    }
    @PostMapping("insert/{uid}")
    public Dto insert(@RequestBody LecturerApply lecturerApply,@PathVariable Integer uid) {
       Dto dto= null;
       int line=0;
       lecturerApply.setUid(uid);
        line = lecturerApplyService.add(lecturerApply);
        if (line > 0) {
         dto  =   DtoUtil.returnSuccessData("添加成功");
        } else {
           dto =DtoUtil.returnError(4002, "添加失败");
        }
        return dto;
    }
    @PostMapping("update/{uid}")
    public Dto update(@RequestBody LecturerApply lecturerApply,@PathVariable Integer uid) {
        Dto dto= null;
        int line=0;
        lecturerApply.setUid(uid);
        lecturerApply.setAudit(1);
        if(EmptyUtils.isEmpty(lecturerApply)){
                dto=DtoUtil.returnError(4001,"参数错误");
        }
        line = lecturerApplyService.update(lecturerApply);
        if (line > 0) {
            dto  =   DtoUtil.returnSuccessData("修改成功");
        } else {
            dto =DtoUtil.returnError(4002, "修改失败");
        }
        return dto;
    }
}

